const getSendData = require("./getSendData");

// 错误处理基类
class ServiceError extends Error {
    constructor(msg, code) {
        super(msg);
        this.code = code;
    }

    toResponseJSON() {
        return getSendData(null, this.code, this.message);
    }
}

exports.ServiceError = ServiceError;

// 文件上传错误
exports.UploadError = class extends ServiceError {
    constructor(msg){
        super(msg);
    }
}

// 禁止访问错误
exports.ForbriddenError = class extends ServiceError {
    constructor(msg){
        super(msg, 401);
    }
}

// 验证错误
exports.ValidationError = class extends ServiceError {
    constructor(msg){
        super(msg, 406);
    }
}

// 无资源错误
exports.NotFoundError = class extends ServiceError {
    constructor(){
        super("Not Found", 404);
    }
}

// 未知错误
exports.UnknownError = class extends ServiceError {
    constructor(){
        super("server internal error", 500);
    }
}
